<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

	<h:head>
	
	<title>Compra</title>
	
	</h:head>
	
	<h:body>

	<p:panel>
		<h:form id="form1">
			<div style="text-align: right;">
				<p:commandButton value="Meu Carrinho" update=":form2" onclick="janela.show()" icon="ui-icon-cart" />
			</div>
			<br />
			
			<p:growl id="message" sticky="false" life="1000" />
			<p:dataGrid value="#{mbProduto.listaProd}" var="prod" columns="3"
				paginator="true" rows="10">

				<p:graphicImage value="image/#{prod.imagem}" style="width:100px;" />
				<br />

				<p:outputLabel value="#{prod.produto}" />

				<p:panelGrid columns="2">
					<p:outputLabel value="Valor: " />
					<p:outputLabel value="#{prod.preco}">
						<f:convertNumber type="currency" />
					</p:outputLabel>
				</p:panelGrid>

				<p:commandButton value="Comprar" icon="ui-icon-check"
					update=":form2,:form1" action="#{mbVenda.adicionarProduto}">
					<p:collector  value="#{prod}" addTo="#{mbVenda.listaSelecionados}"/>
				</p:commandButton>

			</p:dataGrid>



		</h:form>

		<p:dialog header="Carrinho" modal="true" widgetVar="janela">
			<h:form id="form2">
				<p:dataTable value="#{mbVenda.listaSelecionados}" var="prodSelect"
					emptyMessage="Carrinho Vazio">

					<p:column headerText="Produto">
						<p:outputLabel value="#{prodSelect.produto}" />
					</p:column>

					<p:column headerText="Preco">
						<p:outputLabel value="#{prodSelect.preco}" />
					</p:column>


					<p:column headerText="Imagem">
						<p:graphicImage value="image/#{prodSelect.imagem}"
							style="width:70px;" />
					</p:column>


					<p:column>
						<p:commandButton icon="ui-icon-close" id="btRemove" update="@form">
							<p:collector value="#{prodSelect}"
								removeFrom="#{mbVenda.listaSelecionados}" />
						</p:commandButton>

					</p:column>



				</p:dataTable>

				<p:panelGrid columns="2">
					<p:outputLabel value="Total" />
					<p:outputLabel value="#{mbVenda.total}" />
				</p:panelGrid>

             <p:commandButton value="Concluir compra" action="continua_comprado"  ajax="false"/>
             <p:commandButton value="Continua Comprando" onclick="janela.close()"/>

			</h:form>
		</p:dialog>

	</p:panel>


</h:body>
	
	
</html>